<?php
namespace app\admin\controller;

use think\facade\Db;
//use think\facade\Request;
use think\Request;
use think\facade\View;
class Log extends Base
{
    protected $log = null;
    protected $request;

    public function __construct(Request $request)
    {
        $this->log = new \log\Log();
        $this->request=$request;
    }
    public function index(){

        if (false === $this->log->isAllow()) {
            die($this->log->getError());
        }
        $directory = $this->log->getDirectory();
        if ($this->request->isPost()) {
            $filePaths = isset($_GET['file_paths']) ? $_GET['file_paths'] : [];
            $whereFilter = request()->param('filter');
            $whereFilter = $whereFilter ? json_decode($whereFilter, true) : [];
            $rows = $this->log->getLogs($filePaths, $whereFilter);
            $info = $this->log->getInfo($filePaths);
            if (false === $rows) {
                $this->error('获取失败');
            }
            return json(['rows' => $rows, 'info' => $info]);
        }
        View::assign([
            'directory'=>$directory,
        ]);
        return view('index');
    }
    public function aa(){
        $filePaths='201908\08.log';
        $whereFilter='{}';
        $whereFilter = $whereFilter ? json_decode($whereFilter, true) : [];
            $rows = $this->log->getLogs($filePaths, $whereFilter);
            $info = $this->log->getInfo($filePaths);
            var_dump($info);
    }
}